<?php

namespace App\Kuafu\WaiMai\Model;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use App\Kuafu\Base\Model\BaseModel;
use Illuminate\Support\Facades\Log;

class WaiMaiOrderIdShopIdMappingModel extends BaseModel
{
    use HasFactory;

    protected $connection  = 'mysqlWaiMaiAll';
    protected $table       = 'waimai_order_id_shop_id_mappings'; //表名
    protected $primaryKey  = 'orderId';
    public    $timestamps  = false;

    protected $fillable = [
        'orderId',
        'shopId',
        'sourceType',
    ];

    public static function addData(int $orderId, int $shopId, int $sourceType)
    {
        try {
            self::query()->create(['orderId' => $orderId, 'shopId' => $shopId, 'sourceType' => $sourceType]);
        } catch (\Exception $e) {
            Log::warning("WaiMaiOrderIdShopIdMappingModel addData Error: ".$e->getMessage());
        }
    }

    /**
     * 获取shopId
     * @param int $orderId
     * @return int
     */
    public static function getShopId(int $orderId): int
    {
        return (int)self::query()->where('orderId', $orderId)->value('shopId');
    }
}
